<?php

use console\db\Migration;

/**
 * 创建文子直播间相关信息表
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m190102_180239_t_live_chat extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 聊天室（文字直播间）
         * @table `live_chat`
         */
        $this->tableBuilder([
            'name' => 'live_chat',
            'comment' => '聊天室',
            'columns' => [
                'id' => $this->primaryKey(),
                'name' => $this->string(20)->comment('名称'),
                'icon' => $this->char(255)->defaultValue('')->comment('标题'),
                'thumb' => $this->char(255)->defaultValue('')->comment('标题'),
                'model' => $this->char(50)->comment('功能模型'),
                'model_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('模型ID'),
                'expired_at' => $this->unixTimestamp()->comment('结束时间'),
                'listorder' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('展示排序'),
                'rc_status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('融云聊天室状态'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
                'deleted_at' => $this->unixTimestamp()->comment('删除时间'),
            ]
        ]);

        /**
         * 聊天室用户表
         * @table `live_chat_user`.
         */
        $this->tableBuilder([
            'name' => 'live_chat_user',
            'comment' => '聊天室用户表',
            'columns' => [
                'id' => $this->primaryKey(),
                'chat_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('聊天室ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'vote' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('投票类型：0中立，1主，2客'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);


        /**
         * 聊天室主持人信息表
         * @table `live_chat_announcer`.
         */
        $this->tableBuilder([
            'name' => 'live_chat_announcer',
            'comment' => '聊天室主持人信息表',
            'columns' => [
                'id' => $this->primaryKey(),
                'chat_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('聊天室ID'),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('用户ID'),
                'label' => $this->string(50)->defaultValue('')->comment('标签'),
                'username' => $this->string(50)->defaultValue('')->comment('用户名'),
                'avatar' => $this->char(255)->defaultValue('')->comment('头像'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%live_chat_announcer}}');
        $this->dropTable('{{%live_chat_user}}');
        $this->dropTable('{{%live_chat}}');
    }

}
